using UnityEngine;

public class GameUIController : MonoBehaviour
{
	public static GameUIController instance;

	public UIWidget mainui2d;

	public UIWidget mainui3d;

	public GameLoad loadui;

	public PauseUI_level pauseuilevel;

	public ResultUI_level_win resultuilevel_win;

	public ResultUI_level_lose resultuilevel_lose;

	public PauseUITDM pause_tdm;

	public ResultUITDM result_tdm;

	public PauseUIDTB pause_dtb;

	public ResultUIDTB result_dtb;

	public PauseUIFFA pause_ffa;

	public ResultUIFFA result_ffa;

	public PauseUISur pause_sur;

	public ResultUISur result_sur;

	public optionUI optionui;

	public InterfaceUI interfaceui;

	public ShowPieceUI showpieceui;

	public ShowRankUI showrankui;

	public ReliveUI reliveui;

	public GameGuideUI gameguideui;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}

	private void Start()
	{
		mainui2d.alpha = 0f; mainui2d.gameObject.SetActive(false);
		mainui3d.alpha = 0f; mainui3d.gameObject.SetActive(false);
		enable_loading();
	}

	public void showmainui()
	{
		mainui2d.alpha = 1f; mainui2d.gameObject.SetActive(true);
		mainui3d.alpha = 1f; mainui3d.gameObject.SetActive(true);
	}

	public void enable_reliveui()
	{
		Invoke("ablerelive", 3f);
	}

	public void ablerelive()
	{
		if (!GlobalInf.gameover)
		{
			reliveui.enable();
			gamebackctl.instance.ChangeGameUIstate(GameUIState.relive);
		}
	}

	public void disabel_relive()
	{
		reliveui.OnClicknoBtn(null);
	}

	public void enable_inter()
	{
		interfaceui.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.inter);
	}

	public void disable_inter()
	{
		interfaceui.disable();
	}

	public void enable_rankui()
	{
		showrankui.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.rank);
	}

	public void disable_rankui()
	{
		showrankui.disable();
	}

	public void enable_pieceui(PieceData pd)
	{
		showpieceui.enable(pd);
		gamebackctl.instance.ChangeGameUIstate(GameUIState.piece);
	}

	public void disable_pieceui()
	{
		showpieceui.disable();
	}

	public void enable_pause_sur()
	{
		Platform.ShowFeatureView();
		pause_sur.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.pausesur);
		MonoInstance<AudioController>.instance.pauseSounds();
	}

	public void disable_pause_sur()
	{
		Platform.HideFeatureView();
		Time.timeScale = 1f;
		pause_sur.disable();
		gamebackctl.instance.BackGameUIstate();
		MonoInstance<AudioController>.instance.resumeSounds();
	}

	public void enable_result_sur()
	{
		MonoInstance<AudioController>.instance.stopAll();
		result_sur.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.result);
	}

	public void enable_pause_ffa()
	{
		MonoInstance<AudioController>.instance.pauseSounds();
		Platform.ShowFeatureView();
		pause_ffa.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.pauseffa);
	}

	public void disable_pause_ffa()
	{
		Platform.HideFeatureView();
		Time.timeScale = 1f;
		pause_ffa.disable();
		gamebackctl.instance.BackGameUIstate();
		MonoInstance<AudioController>.instance.resumeSounds();
	}

	public void enable_result_ffa()
	{
		MonoInstance<AudioController>.instance.stopAll();
		result_ffa.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.result);
	}

	public void enable_pause_dtb()
	{
		MonoInstance<AudioController>.instance.pauseSounds();
		Platform.ShowFeatureView();
		pause_dtb.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.pausedtb);
	}

	public void disable_pause_dtb()
	{
		Platform.HideFeatureView();
		Time.timeScale = 1f;
		pause_dtb.disable();
		gamebackctl.instance.BackGameUIstate();
		MonoInstance<AudioController>.instance.resumeSounds();
	}

	public void enable_result_dtb()
	{
		MonoInstance<AudioController>.instance.stopAll();
		result_dtb.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.result);
	}

	public void enable_pause_tdm()
	{
		MonoInstance<AudioController>.instance.pauseSounds();
		Platform.ShowFeatureView();
		pause_tdm.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.pausetdm);
	}

	public void disable_pause_tdm()
	{
		Platform.HideFeatureView();
		Time.timeScale = 1f;
		pause_tdm.disable();
		gamebackctl.instance.BackGameUIstate();
		MonoInstance<AudioController>.instance.resumeSounds();
	}

	public void enable_result_tdm()
	{
		MonoInstance<AudioController>.instance.stopAll();
		result_tdm.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.result);
	}

	public void enable_loading()
	{
		loadui.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.loading);
	}

	public void enable_pauseui_level()
	{
		MonoInstance<AudioController>.instance.pauseSounds();
		Platform.ShowFeatureView();
		pauseuilevel.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.pauselevel);
	}

	public void disable_pauseui_level()
	{
		Platform.HideFeatureView();
		Time.timeScale = 1f;
		pauseuilevel.disable();
		gamebackctl.instance.BackGameUIstate();
		MonoInstance<AudioController>.instance.resumeSounds();
	}

	public void enable_optionui()
	{
		optionui.enable();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.option);
	}

	public void disable_optionui()
	{
		optionui.disable();
		switch (gamebackctl.instance.curstate)
		{
			case GameUIState.pauselevel:
				pauseuilevel.enable();
				break;
			case GameUIState.pausedtb:
				pause_dtb.enable();
				break;
			case GameUIState.pauseffa:
				pause_ffa.enable();
				break;
			case GameUIState.pausesur:
				pause_sur.enable();
				break;
			case GameUIState.pausetdm:
				pause_tdm.enable();
				break;
			case GameUIState.normal:
				Time.timeScale = 1f;
				break;
		}
	}

	public void enable_resultui_level(bool issuc)
	{
		MonoInstance<AudioController>.instance.stopAll();
		gamebackctl.instance.ChangeGameUIstate(GameUIState.result);
		if (issuc)
		{
			if (GamePlayerprefs.instance.levelfirst_win == 1)
			{
				Platform.flurryEvent_level(GlobalInf.CurrentLevel, 2);
				GamePlayerprefs.instance.setlevel_first_win(GlobalInf.CurrentLevel);
			}
			Platform.flurryEvent_level(GlobalInf.CurrentLevel, 3);
			resultuilevel_win.enable();
			return;
		}
		if (GamePlayerprefs.instance.levelfirst_lose == 1)
		{
			Platform.flurryEvent_level(GlobalInf.CurrentLevel, 4);
			GamePlayerprefs.instance.setlevel_first_lose(GlobalInf.CurrentLevel);
		}
		Platform.flurryEvent_level(GlobalInf.CurrentLevel, 5);
		if (GamePlayerprefs.instance.falsefirst == 1)
		{
			resultuilevel_lose.enable(showguide: true);
			GamePlayerprefs.instance.setmenufirst();
		}
		else
		{
			resultuilevel_lose.enable(showguide: false);
		}
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}
}
